import request from '@/utils/request'
import 'echarts/extension/bmap/bmap'
export default {
  // 分页查询
  getCourierListPage(page, limit, courierQuery) {
    return request({
      url: `/e/courier/pageTeacherCondition/${page}/${limit}`,
      method: 'post',
      data: courierQuery
    })
  }, // 通过Id删除
  removeById(id) {
    return request({
      url: `/e/courier/removeCourier/${id}`,
      method: `delete`
    })
  },
  // 添加讲师
  add(courier) {
    return request({
      url: `/e/courier/addCourier`,
      method: 'post',
      data: courier
    })
  },
  // 根据id查询讲师
  getCourierInfo(id) {
    return request({
      url: `/e/courier/findCourierById/${id}`,
      method: 'get'
    })
  },
  // 更新快递员
  updateCourierById(courier) {
    return request({
      url: `/e/courier/updateCourierById`,
      method: 'post',
      data: courier
    })
  },
  // 获取控制台数据
  getConsoleInfo() {
    return request({
      url: `/e/courier/console`,
      method: 'get'
    })
  },
  loadBMap(ak) {
    return new Promise(function(resolve, reject) {
      if (typeof BMap !== 'undefined') {
        // eslint-disable-next-line no-undef
        resolve(BMap)
        return true
      }
      window.onBMapCallback = function() {
        // eslint-disable-next-line no-undef
        resolve(BMap)
      }
      const script = document.createElement('script')
      script.type = 'text/javascript'
      script.src =
            'http://api.map.baidu.com/api?v=2.0&ak=' + ak + '&callback=onBMapCallback'
      script.onerror = reject
      document.head.appendChild(script)
    })
  },
  deletes(ids) {
    return request({
      url: `/e/courier/deletes`,
      method: 'post',
      data: ids
    })
  }
}
